#include "dbconnhelper.h"
#include "inifilehelper.h"

DbConnHelper::DbConnHelper() {}

QSqlDatabase DbConnHelper::openDataBase(QString connectionnName, QString Table)
{
    if ( true == QSqlDatabase::contains(connectionnName))
    {
        db = QSqlDatabase::database(connectionnName); //存在就使用这个连接
    }else {
        db = QSqlDatabase::addDatabase("QODBC", connectionnName);
        db.setHostName(IniFilehelper::hostName);
        db.setUserName(IniFilehelper::User);
        db.setPassword(IniFilehelper::Pwd);
        db.setDatabaseName(Table);
        if(!db.open()){
            qDebug()<<"打开数据库"<<Table<<"失败!";
        }
    }
    return db;
}

void DbConnHelper::closeDataBase(QString connectionName)
{
    db.close();
    QSqlDatabase::removeDatabase(connectionName);
}
